package com.woniu.controller;

import com.woniu.entity.Order;
import com.woniu.entity.vo.OrderVo;
import com.woniu.service.OrderService;
import com.woniu.util.PageData;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    public ResData<?> addOrder(@RequestBody OrderVo orderVo, HttpServletRequest request){
//        System.out.println("============================");
//        System.out.println(orderVo);
        String jwt = request.getHeader("token");
        return orderService.addOrder(orderVo,jwt);
    }

    @PostMapping("/queryOrder")
    public ResData<?> queryOrder(@RequestBody PageData<Order> pageData,HttpServletRequest request){
        String jwt = request.getHeader("token");
        return orderService.queryOrder(pageData,jwt);
    }

    @PostMapping("/confirmOrder")
    public ResData<?> confirmOrder(@RequestBody Order order){
        return orderService.confirmOrder(order);
    }

    @GetMapping("/cancelOrder")
    public ResData<?> cancelOrder(String orderNum){
        return orderService.cancelOrder(orderNum);
    }

    @GetMapping("/payOrder")
    public ResData<?> payOrder(String orderNum){
        return orderService.payOrder(orderNum);
    }

    @PostMapping ("/comment")
    public ResData<?> comment(String orderNum,Integer score,String comment){
        return orderService.comment(orderNum,score,comment);
    }
}
